<?php
//解释WIKI，生成TOOLKIT所需要的JS数据
exit;
$s = file_get_contents("errNo.txt");

$s = preg_replace("#\n\s+#","\n",$s);
//echo $s;
$p = preg_match_all("#\n\d{6}\s+([a-z0-9/_\*]+)\s+[^\n]+\n#sim",$s, $m);

$errNo = array();

foreach ($m[1] as $i=>$v){
	if (strpos($v,"*")!==false){
		$v = '___';
	}else{
		$v = '/'.ltrim($v,'/');
	}
	$errNo[$v].="\r\n".trim($m[0][$i]);
}

file_put_contents("errNoJsonData.txt",json_encode($errNo));

exit;








exit;
//以下是分析参数部分
function getApis(){
	$url = 'http://docs.php.sinagz';
	$p="#\shref=\"(/index.php/VYJ-API::/.+?)\"\s#sim";

	$s = file_get_contents('http://docs.php.sinagz/index.php/%E5%BE%AE%E6%B8%B8%E8%AE%B0');
	preg_match_all($p, $s, $m);
	$apis = $m[1];

	$s = file_get_contents('http://docs.php.sinagz/index.php/%E7%88%B1%E8%87%AA%E6%B8%B8API%E6%96%87%E6%A1%A3');
	preg_match_all($p, $s, $m2);

	$apis = array_merge($apis, $m2[1]);
	$rst = array();
	foreach ($apis as $v){
		$k = substr($v, 20);
		$rst[$k] = $url.$v;
	}
	return $rst;
}

function getApiParamData($url){
	$s = file_get_contents($url);
	$p = "#参数列表.+?</h2>(.+?)<h2>#sim";
	preg_match_all($p,$s,$m);
	$pstr = $m[1][1];
	$pstr = trim(strip_tags($pstr));
	$pstr = preg_replace("#\n\s+#","\n",$pstr);
	$pt = explode("\n",$pstr);
	$parr = array();
	
	if (strpos($pt[0], "类型及范围")){
		foreach ($pt as $v ){
			$v = trim($v);
			$parr = array_merge($parr, preg_split("#\s+#", $v, 4));
		}
		
		
	}else{
		$parr = $pt;
	}
	$parr = array_slice($parr, 4);
	
	
	//参数配置分析结果
	$rst = array();
	
	$pi = 0;
	while(true){
		$pi+=4;
		if (!isset($parr[$pi-1])){
			break;
		}
		$n = trim($parr[$pi-4]);
		$yes = strtolower(trim($parr[$pi-3])) == 'true' ? true : false;
		$rst[$n] = array(
			'name' => $n,
			'yes' => $yes,
			'type' => trim($parr[$pi-2]),
			'desc' => trim($parr[$pi-1])
		);

	}
	
	return $rst;
}

/*
getApiParamData('http://docs.php.sinagz/index.php/VYJ-API::/account/update_password');
echo "\n";
getApiParamData('http://docs.php.sinagz/index.php/VYJ-API::/footmark/set');
exit;
*/

function getAllApi(){
	$rst = array();
	$apis = getApis();
	foreach ($apis as $r=>$api){
		$rst[$r] = getApiParamData($api);
		echo "已处理完接口 $api \n";
		//print_r($rst[$r]);
	}
	return $rst;
}


$apiData = getAllApi();
file_put_contents('apidata.json.txt',json_encode($apiData));
exit;

